﻿using SmartHRMS.Model.Account;
using System.Collections.Generic;
using System;

namespace SmartHRMS.NhibernateRepository.Repositories
{
    public class RoleRepository : BaseRepository<Role>, IRoleRepository
    {
        public bool IsRoleNameExist(string roleName)
        {
            var result = SessionFactory.GetCurrentSession().CreateQuery("select o from Role o where o.Name = :Name").SetString("Name", roleName);
            if (result.List().Count > 0)
            {
                return true;
            }
            return false;
        }

        #region IRoleRepository Members

        public void RevokePermissions(Guid roleId)
        {
            SessionFactory.GetCurrentSession().CreateSQLQuery("delete from Accounts_RolePermissions where RoleId='" + roleId + "'").ExecuteUpdate();
        }

        public void GrantPermissions(IList<Permission> permission)
        {
        }
        #endregion
    }
}
